<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑护理服务记录表</title>
	<#include "/common/resource.ftl">
    <link rel="stylesheet" href="${params.contextPath}/static/plug/layui/css/layui.css">
    <link rel="stylesheet" href="${params.contextPath}/static/css/jquery-ui.min.css">
    <script src="${params.contextPath}/static/js/jquery-ui.min.js"></script>
    <style>
        .layui-form select {display:none !important;}
    </style>
	<script type="text/javascript">
		$(function () {
            <#if (params.tag)??>
            $( "#elderName").autocomplete({
                source: function(request, response) {
                    $.ajax({
                        url: "${params.contextPath}/web/elder/listAll.json",
                        dataType: "json",
                        data: {
                            name: $("#elderName").val().trim()
                        },
                        success: function(data) {
                            response($.map(data.data, function(item) {
                                return {
                                    value: item.name,
                                    id: item.id
                                }
                            }));
                        }
                    });

                },
                select: function(e, ui) {
                    $("[name='elderId']").val(ui.item.id);
                },
                maxLength: 2
            });
            <#else>
            LocalStorage.registHandler("elder_handler_select", function (data) {
                $('input[name="elderId"]').val(data.id);
                $('input[name="elderName"]').val(data.name);
            });
            </#if>
			<#if (params.id)??>
				$.ajaxRequest({
					url: '${params.contextPath}/web/nursingServiceRecord/query.json',
					data: {id: "${params.id}"},
					success: function (data) {
						if (!data.success) {
							$.message(data.message);
							return;
						}
						var record = data.data;
						for (var key in record) {
                            if (key == 'feedingMedicine') {
                                var feedingMedicine = record.feedingMedicine;
                                var feedingMedicineArray = feedingMedicine.split(",");
                                var feedingMedicineAll = $("input[name='feedingMedicine']");
                                for(var i=0; i<feedingMedicineArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(feedingMedicineAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(feedingMedicineArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'foodHelp') {
                                var foodHelp = record.foodHelp;
                                var foodHelpArray = foodHelp.split(",");
                                var foodHelpAll = $("input[name='foodHelp']");
                                for(var i=0; i<foodHelpArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(foodHelpAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(foodHelpArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'dailyPersonalHygiene') {
                                var dailyPersonalHygiene = record.dailyPersonalHygiene;
                                var dailyPersonalHygieneArray = dailyPersonalHygiene.split(",");
                                var dailyPersonalHygieneAll = $("input[name='dailyPersonalHygiene']");
                                for(var i=0; i<dailyPersonalHygieneArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(dailyPersonalHygieneAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(dailyPersonalHygieneArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'bedCleaning') {
                                var bedCleaning = record.bedCleaning;
                                var bedCleaningArray = bedCleaning.split(",");
                                var bedCleaningAll = $("input[name='bedCleaning']");
                                for(var i=0; i<bedCleaningArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(bedCleaningAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(bedCleaningArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else {
                                $("[name='" + key + "']").val(record[key]);
                            }

						}
						layui.form.render();
					}
				});
			</#if>
            $(".ajax-form").unbind().submit(function () {
                try {
                    var form = $(this);
                    if (!form.valid()) {
                        $.message("验证不通过，无法提交表单");
                        return false;
                    }

                    form.formSubmit({
                        callBack:function (data) {
                            <#if (params.tag)??>
                            history.go(-1);
                            </#if>
                        }
                    });
                } catch (e) {
                    console.log("表单提交错误：" + e);
                }
                return false;
            });
		});
	</script>
</head>
<body>
	<div class="ui-form">
		<form class="layui-form ajax-form" action="${params.contextPath}/web/nursingServiceRecord/<#if (params.id)??>modify<#else>save</#if>.json" method="post">
			<input type="hidden" name="id" value="${params.id}" />
            <#if (params.tag)??>
                <div class="layui-form-item">
                    <label class="layui-form-label">老人<span class="ui-request">*</span></label>
                    <div class="layui-input-block">
                        <input type="hidden" name="elderId" id="elderId" value=""/>
                        <input type="text" id="elderName" name="elderName" class="layui-input" autocomplete="off"/>
                    </div>
                </div>
            <#else>
                <div class="layui-form-item">
                    <label class="layui-form-label">老人<span class="ui-request">*</span></label>
                    <div class="layui-input-block">
                        <input type="hidden" name="elderId"/>
                        <input type="text" name="elderName" placeholder="请选择老人" p="model:'elder',handlerId:'elder_handler_select'" class="layui-input single-model-select {required:true}" readonly>
                    </div>
                </div>
            </#if>
			<div class="layui-form-item">
                <label class="layui-form-label">喂药<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <input type="checkbox" name="feedingMedicine" value="早" title="早">
                    <input type="checkbox" name="feedingMedicine" value="中" title="中">
                    <input type="checkbox" name="feedingMedicine" value="晚" title="晚">
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">助餐<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <input type="checkbox" name="foodHelp" value="早" title="早">
                    <input type="checkbox" name="foodHelp" value="中" title="中">
                    <input type="checkbox" name="foodHelp" value="晚" title="晚">
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">日常个人卫生<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <input type="checkbox" name="dailyPersonalHygiene" value="洗澡" title="洗澡">
                    <input type="checkbox" name="dailyPersonalHygiene" value="洗头" title="洗头">
                    <input type="checkbox" name="dailyPersonalHygiene" value="洗脸" title="洗脸">
                    <input type="checkbox" name="dailyPersonalHygiene" value="洗脚" title="洗脚">
                    <input type="checkbox" name="dailyPersonalHygiene" value="理发" title="理发">
                    <input type="checkbox" name="dailyPersonalHygiene" value="修面" title="修面">
                    <input type="checkbox" name="dailyPersonalHygiene" value="刷牙" title="刷牙">
                    <input type="checkbox" name="dailyPersonalHygiene" value="漱口" title="漱口">
                    <input type="checkbox" name="dailyPersonalHygiene" value="擦身" title="擦身">
                    <input type="checkbox" name="dailyPersonalHygiene" value="修指甲" title="修指甲">
                    <input type="checkbox" name="dailyPersonalHygiene" value="清洁假牙" title="清洁假牙">
                    <input type="checkbox" name="dailyPersonalHygiene" value="换内衣" title="换内衣">
                    <input type="checkbox" name="dailyPersonalHygiene" value="换外衣" title="换外衣">
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">床单元保洁<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <input type="checkbox" name="bedCleaning" value="换床单" title="换床单">
                    <input type="checkbox" name="bedCleaning" value="换被套" title="换被套">
                    <input type="checkbox" name="bedCleaning" value="换枕套" title="换枕套">
                    <input type="checkbox" name="bedCleaning" value="衣物整理" title="衣物整理">
                </div>
            </div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="submit" value="保存" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</body>
<script src="${params.contextPath}/static/plug/layui/layui.all.js"></script>
</html>
